package com.fingard.dsp.bank.directbank.bocom01;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.IAuthorizeForRec;
import com.fingard.dsp.bank.reqrespobj.authforrec.*;
import com.fingard.dsp.bank.reqrespobj.authforrec.detail.RetAtsQryAuthForRecDetail;
import com.fingard.dsp.bank.reqrespobj.authforrec.detail.RetAtsQryRecAuthInfoDetail;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.util.Date;

public class BOCOM01AuthorizeForRec extends BOCOM01Base implements IAuthorizeForRec {
    @Override
    public RetAtsAuthForRec d_auth(ReqAuthForRec p_req) {
        return d_auth_old(p_req);
    }

    public RetAtsAuthForRec d_auth_old(ReqAuthForRec p_req) {
        RetAtsAuthForRec tmpRetAts = new RetAtsAuthForRec(p_req.reqHeader);
        try {
            XmlTextWriter xmlWriter = new XmlTextWriter();//
            tr_code = BOCOM01TransType.code940103;
            writeCommonHeader(xmlWriter);
            XElement tmpXElement = new XElement("body", "");
            tmpXElement.addChild(new XElement("PtcId", p_req.authAgNum));
            tmpXElement.addChild(new XElement("TranTyp", "0"));
            tmpXElement.addChild(new XElement("MobileNo", ""));
            tmpXElement.addChild(new XElement("Rmk", ""));
            tmpXElement.addChild(new XElement("TranNum", p_req.totalNum));
            XElement subProtocList = new XElement("SubProtocList", "");
            while (p_req.readRecord()) {
                XElement subProtocDetail = new XElement("SubProtocDetail", "");
                subProtocDetail.addChild(new XElement("PayAccNo", p_req.readedDetail.oppAct));
                subProtocDetail.addChild(new XElement("PayAccName", p_req.readedDetail.oppActName));
                subProtocDetail.addChild(new XElement("CtfTyp", convertCertTypeToBank(p_req.readedDetail.certType)));
                subProtocDetail.addChild(new XElement("CtfNo", p_req.readedDetail.certNum));
                String singleLimit = getBankConfig().getMapValueByKey("contractKeyMapping", "singleLimit");
                if (StringHelper.isNullOrEmpty(singleLimit)) {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = "缺失配置节点'SingleLimit'或值为空!";
                    return tmpRetAts;
                }
                subProtocDetail.addChild(new XElement("SingleLimit", singleLimit));
                String dayAmtLimit = getBankConfig().getMapValueByKey("contractKeyMapping", "dayAmtLimit");
                if (StringHelper.isNullOrEmpty(dayAmtLimit)) {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = "缺失配置节点'dayAmtLimit'或值为空!";
                    return tmpRetAts;
                }
                subProtocDetail.addChild(new XElement("DayLimit", dayAmtLimit));
                String monthAmtLimit = getBankConfig().getMapValueByKey("contractKeyMapping", "monthAmtLimit");
                if (StringHelper.isNullOrEmpty(monthAmtLimit)) {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = "缺失配置节点'monthAmtLimit'或值为空!";
                    return tmpRetAts;
                }
                subProtocDetail.addChild(new XElement("MonthLimit", monthAmtLimit));
                subProtocDetail.addChild(new XElement("Moblie", p_req.readedDetail.cellPhone));
                subProtocDetail.addChild(new XElement("Email", ""));
                subProtocDetail.addChild(new XElement("Remark", ""));
                subProtocDetail.addChild(new XElement("ProtocEffectDate", Format.Date8Format.format(new Date())));
                String deadLine = getBankConfig().getMapValueByKey("contractKeyMapping", "deadLine");
                if (StringHelper.isNullOrEmpty(deadLine)) {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = "缺失配置节点'deadLine'或值为空!";
                    return tmpRetAts;
                }
                subProtocDetail.addChild(new XElement("ProtocInvalidDate", deadLine));
                String periodLimit = getBankConfig().getMapValueByKey("contractKeyMapping", "periodLimit");
                if (StringHelper.isNullOrEmpty(periodLimit)) {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = "缺失配置节点'periodLimit'或值为空!";
                    return tmpRetAts;
                }
                if ("1".equals(periodLimit)) {
                    periodLimit = "D";
                } else if ("2".equals(periodLimit)) {
                    periodLimit = "M";
                } else {
                    periodLimit = "Y";
                }
                subProtocDetail.addChild(new XElement("Period", periodLimit));
                subProtocDetail.addChild(new XElement("AddInfo", p_req.readedDetail.sourceNoteCode));
                subProtocList.addChild(subProtocDetail);
            }
            tmpXElement.addChild(subProtocList);
            xmlWriter.writeXElement(tmpXElement);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());

            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                // 解析银行返回
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {

                    String tmpStrParCode = tmpBkReader.getFirstText("/ap/head/particular_code");
                    String tmpStrParInfo = tmpBkReader.getFirstText("/ap/head/particular_info");

                    if (!StringHelper.isNullOrEmpty(tmpStrParCode)) {
                        tmpRetAts.respCode = "0";
                        String errCode = tmpBkReader.getFirstText("/ap/body/ErrCode");
                        String successFlg = tmpBkReader.getFirstText("/ap/body/SuccessFlg");
                        if ("0".equals(successFlg)) {
                            tmpRetAts.retCode = "0";
                        } else {
                            tmpRetAts.retCode = errCode;
                        }
                        tmpRetAts.retMsg = tmpBkReader.getFirstText("/ap/body/ErrMsg");
                    } else {
                        tmpRetAts.respCode = "-1";
                        tmpRetAts.respInfo = tmpStrParInfo;
                    }
                } else {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetAts.respCode = "-1";
                tmpRetAts.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            tmpRetAts.respCode = "-1";
            tmpRetAts.respInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }
        tmpRetAts.writeRetToATS();
        return tmpRetAts;
    }

    public RetAtsAuthForRec d_auth_new(ReqAuthForRec p_req) {
        RetAtsAuthForRec tmpRetAts = new RetAtsAuthForRec(p_req.reqHeader);
        try {
            tr_code = "FHTS01";
            String transCode = "400101";
            String contractNo = getBankConfig().getMapValueByKey("cagrNo" + transCode, p_req.ownAct);
            //暂时不支持批量
            if (p_req.readRecord()) {
                XmlTextWriter xmlWriter = new XmlTextWriter();// 发银行报文的XML对象
                // 写入通用的头部节点
                writeCommonHeader(xmlWriter);
                xmlWriter.writeStartElement("body");
                XElement dataElement = new XElement("data", "");
                dataElement.addChild(new XElement("transCode", transCode));//交易码
                dataElement.addChild(new XElement("subdate", Format.Date8Format.format(new Date())));//委托日期 格式YYYYMMDD
                dataElement.addChild(new XElement("outid", p_req.reqSeqID));//交易序号
                dataElement.addChild(new XElement("contracttype", "0"));//协议标识  0-收,1-付 （目前只提供代收业务）
                dataElement.addChild(new XElement("chgtype", "100"));//协议操作标识 100-增加，101-变更 ， 102-撤销
                dataElement.addChild(new XElement("sndOrgNo", bankFront.org));//收费机构代码
                dataElement.addChild(new XElement("sndBranchNo", ""));//机构分支代码
                dataElement.addChild(new XElement("contractno", contractNo));//协议号 变更时必输
                dataElement.addChild(new XElement("custno", getValueAsString("custno")));//用户编号
                dataElement.addChild(new XElement("cusNme", getValueAsString("cusNme")));//用户名称
                dataElement.addChild(new XElement("payername", ""));//联系人名称 变更时必输
                dataElement.addChild(new XElement("addr", ""));//联系人地址 变更时必输
                dataElement.addChild(new XElement("contZipCde", ""));//联系人地址邮编 变更时必输
                dataElement.addChild(new XElement("tel", ""));//联系人电话 变更时必输
                dataElement.addChild(new XElement("busKnd", getBankConfig().getMapValueByKey("PayType", p_req.payType)));//业务种类
                dataElement.addChild(new XElement("bankno", "01310401999"));//付款行行号
                dataElement.addChild(new XElement("acctno", p_req.readedDetail.oppAct));//付款人账号
                dataElement.addChild(new XElement("acctname", p_req.readedDetail.oppActName));//付款人名称
                dataElement.addChild(new XElement("payeridtype", convertCertTypeToBank(p_req.readedDetail.certType)));//付款人证件类型
                dataElement.addChild(new XElement("payerid", p_req.readedDetail.certNum));//付款人证件号码
                dataElement.addChild(new XElement("payTel", ""));//付款人手机号码 变更时必输
                dataElement.addChild(new XElement("payEmail", ""));//付款人电子邮箱 变更时必输
                dataElement.addChild(new XElement("signDate", Format.Date8Format.format(new Date())));//签约起始日期 格式YYYYMMDD
                dataElement.addChild(new XElement("signEndDate", p_req.readedDetail.deadLine));//到期日期 格式YYYYMMDD
                dataElement.addChild(new XElement("desc", ""));//附言
                dataElement.addChild(new XElement("remark", ""));//备注
                xmlWriter.writeXElement(dataElement);
                xmlWriter.writeEndDocument();
                String[] bankResult = sendToBank(xmlWriter.toXmlString());
                if (bankResult[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(bankResult[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        tmpRetAts.respCode = "0";
                        String ans_code = tmpBkReader.getFirstText("/ap/head/ans_code");
                        String responseCode = tmpBkReader.getFirstText("/ap/body/responseCode");
                        String ans_info = tmpBkReader.getFirstText("/ap/head/ans_info");
                        if ("0".equals(ans_code)) {
                            if ("000000".equals(responseCode)) {
                                tmpRetAts.retCode = "0";
                                tmpRetAts.serialNo = tmpBkReader.getFirstText("/ap/body/transno");
                            } else {
                                tmpRetAts.retCode = "1";
                            }
                            tmpRetAts.retMsg = tmpBkReader.getFirstText("/ap/body/responseMessage");
                        } else {
                            tmpRetAts.retCode = "2";
                            tmpRetAts.retMsg = ans_info;
                        }
                        tmpRetAts.reqSeqID = p_req.reqSeqID;
                    } else {
                        tmpRetAts.respCode = "-1";
                        tmpRetAts.respInfo = tmpSbMsg.toString();
                    }

                } else {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = bankResult[1];
                }
            } else {
                tmpRetAts.respCode = "-1";
                tmpRetAts.respInfo = "读取detail为空";
            }
        } catch (Exception ex) {
            tmpRetAts.respCode = "-1";
            tmpRetAts.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        tmpRetAts.writeRetToATS();
        return tmpRetAts;

//        RetAtsAuthForRec tmpRetAts = new RetAtsAuthForRec(p_req.reqHeader);
//        tmpRetAts.respCode = "-1";
//        tmpRetAts.respInfo = "银行目前暂不支持线上签约！";
//        tmpRetAts.writeRetToATS();
//        return tmpRetAts;
    }

    @Override
    public RetAtsQryAuthForRec d_qry_auth(ReqQryAuthForRec p_req) {
        RetAtsQryAuthForRec retAts = new RetAtsQryAuthForRec(p_req.reqHeader);
        retAts.reqSeqID = p_req.reqSeqID;
        retAts.writeStart();

        try {
            XmlTextWriter xmlWriter = new XmlTextWriter();//
            tr_code = BOCOM01TransType.code940101;
            writeCommonHeader(xmlWriter);
            XElement tmpXElement = new XElement("body", "");
            tmpXElement.addChild(new XElement("PtcId", p_req.authAgNum));
            tmpXElement.addChild(new XElement("StartUpdDtTm", Format.Date8Format.format(new Date())));
            String deadLine = getBankConfig().getMapValueByKey("contractKeyMapping", "deadLine");
                if (StringHelper.isNullOrEmpty(deadLine)) {
                    retAts.respCode = "-1";
                    retAts.respInfo = "缺失配置节点'deadLine'或值为空!";
                    return retAts;
                }
            tmpXElement.addChild(new XElement("EndUpdDtTm", deadLine));
            tmpXElement.addChild(new XElement("PayAccNo", p_req.ownAct));
            tmpXElement.addChild(new XElement("SubProtocStt", "0"));
            tmpXElement.addChild(new XElement("Offset", "0"));
            tmpXElement.addChild(new XElement("PageSize", "20"));
            xmlWriter.writeXElement(tmpXElement);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());

            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                // 解析银行返回
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getFirstText("/ap/head/particular_code");
                    String tmpRetMsg = tmpBkReader.getFirstText("/ap/head/particular_info");
                    if (!StringHelper.isNullOrEmpty(tmpRetCode)) {
                        if (isActiveRetCode(tmpRetCode)) {
                            String serial_record = tmpBkReader.getFirstText("/ap/body/serialRecord");
                            int FieldNum = Integer.parseInt(tmpBkReader.getFirstText("/ap/body/field_num"));
                            int RecordNum = Integer.parseInt(tmpBkReader.getFirstText("/ap/body/record_num"));
                            java.util.List<String[]> listStrings = DealMFSText(serial_record, '|', FieldNum, RecordNum);

                            retAts.respCode = "0";
                            if (listStrings.size() > 0) {
                                listStrings.remove(0);
                                for (String[] strings : listStrings) {
                                    RetAtsQryAuthForRecDetail tmpRetDetail = new RetAtsQryAuthForRecDetail();

                                    /**
                                     主协议编号(C20)|  0
                                     子协议编号(C27)|  1
                                     付款账号(C30)|  2
                                     户名(C100)|  3
                                     币种(C3)|  4
                                     证件类型(C5)|  5
                                     证件号码(C50)|  6
                                     单笔限额(N15.5)|  7
                                     日累计限额(N15.5)|  8
                                     月累计限额(N15.5)|  9
                                     手机号(C25)|  10
                                     Email（C50）|  11
                                     备注(C50)|  12
                                     协议生效日期(C8)|  13
                                     协议失效日期(C8)|  14
                                     协议状态(C1)|  15
                                     签约渠道(C1)|  16
                                     最后维护日期(C8)|  17
                                     扣费周期(C1)|  18
                                     附加信息(C100)|  19
                                     备用字段1(C100)|  20
                                     备用字段2(C100)|  21
                                     备用字段3(C100)|  22
                                     */
                                    tmpRetDetail.oppAct = strings[2];
                                    tmpRetDetail.oppActName = strings[3];
                                    String status = strings[15];
                                    if ("0".equals(status) || "1".equals(status) || "3".equals(status)) {
                                        tmpRetDetail.transState = "4";
                                    } else if ("2".equals(status)) {
                                        tmpRetDetail.transState = "2";
                                    } else {
                                        tmpRetDetail.transState = "3";
                                    }
                                    retAts.writeRetDetail(tmpRetDetail);
                                }
                            } else {
                                retAts.respCode = "-1";
                                retAts.respInfo = tmpRetMsg;
                            }
                        } else {
                            retAts.respCode = "-1";
                            retAts.respInfo = tmpRetMsg;
                        }
                    } else {
                        retAts.respCode = "-1";
                        retAts.respInfo = "节点/ap/head/particular_code为空";
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            retAts.respCode = "-1";
            retAts.respInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }
        
        retAts.writeAfterDetail();
        return retAts;
    }

    @Override
    public RetAtsQryRecAuthInfo d_qry_authInfo(ReqQryRecAuthInfo p_req) throws Exception {
        return d_qry_authInfo_old(p_req);
    }

    public RetAtsQryRecAuthInfo d_qry_authInfo_old(ReqQryRecAuthInfo p_req) throws Exception {
        RetAtsQryRecAuthInfo tmpRetAts = new RetAtsQryRecAuthInfo(p_req.reqHeader);
        try {
            tr_code = "210403";
            String data_end = "1";
            int offset = 0;
            String tmpRespCode = "";
            String tmpRespInfo = "";
            String contractNo = getBankConfig().getMapValueByKey("cagrNo" + tr_code, p_req.ownAct);
            boolean matchOppAct = !StringHelper.isNullOrEmpty(p_req.oppAct);
            while (!"0".equals(data_end) && tmpRespCode.length() == 0) {
                XmlTextWriter xmlWriter = new XmlTextWriter();// 发银行报文的XML对象
                // 写入通用的头部节点
                writeCommonHeader(xmlWriter);
                xmlWriter.writeStartElement("body");
                xmlWriter.writeElementString("cagrNo", contractNo);
                xmlWriter.writeElementString("pageSize", "50");
                xmlWriter.writeElementString("beginPos", offset * 50 + "");
                xmlWriter.writeEndDocument();
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                XmlTextReader tmpBkReader;
                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/ap/head/particular_code");
                        String tmprspmsg = tmpBkReader.getFirstText("/ap/head/particular_info");
                        if (isActiveRetCode(tmpRetCode)) {
                            String jj = tmpBkReader.getFirstText("/ap/body/data_end");
                            if ("".equals(jj)) {
                                data_end = "0";
                            } else {
                                data_end = tmpBkReader.getFirstText("/ap/body/dataEnd");
                                offset++;
                            }
                            String serial_record = tmpBkReader.getFirstText("/ap/body/serialRecord");
                            int FieldNum = Integer.parseInt(tmpBkReader.getFirstText("/ap/body/fieldNum"));
                            int RecordNum = Integer.parseInt(tmpBkReader.getFirstText("/ap/body/recordNum"));
                            java.util.List<String[]> listStrings = DealMFSText(serial_record, '|', FieldNum, RecordNum);
                            if (listStrings.size() > 0) {
                                listStrings.remove(0);
                                for (String[] strings : listStrings) {
                                    //0.付款签约编号(C30)|1.付款账号(C40)|2.付款户名(C60)|3.缴费户名(C60)|4.自定义字段值(C200)|5.单笔限额(C15)|6.当日累计限额(C15)|7.当月累计限额(C15)|8.是否需要确认后扣款(C1)|9.证件类型(C2)|10.证件号码(30)|11.协议生效日期(C8)|12.协议失效日期(C8)|13.收款方式(C1)
                                    if (!matchOppAct || strings[1].equals(p_req.oppAct)) {
                                        tmpRetAts.respCode = "0";
                                        tmpRetAts.ownAct = p_req.ownAct;
                                        RetAtsQryRecAuthInfoDetail tmpDetail = new RetAtsQryRecAuthInfoDetail();
                                        tmpDetail.oppAct = strings[1];
                                        tmpDetail.oppActName = strings[2];
                                        tmpDetail.queryTag = p_req.queryTag;
                                        tmpDetail.respReserve2 = strings[0];
                                        tmpDetail.respReserve1 = contractNo;
                                        tmpDetail.respReserve3 = strings[3];
                                        tmpRetAts.writeRetDetail(tmpDetail);
                                    }
                                }
                            } else {
                                tmpRespCode = "-1";
                                tmpRespInfo = tmprspmsg;
                                break;
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmprspmsg;
                            break;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                        break;
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpStrRet[1];
                    break;
                }
            }
            if (tmpRespCode.length() == 0) {
                tmpRespCode = "0";
                tmpRespInfo = "查无该收方签约信息，请核对！";
            }
            tmpRetAts.respCode = tmpRespCode;
            tmpRetAts.respInfo = tmpRespInfo;
            tmpRetAts.ownAct = p_req.ownAct;
        } catch (Exception ex) {
            tmpRetAts.respCode = "-1";
            tmpRetAts.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        tmpRetAts.writeAfterDetail();
        return tmpRetAts;
    }


    public RetAtsQryRecAuthInfo d_qry_authInfo_new(ReqQryRecAuthInfo p_req) throws Exception {
        RetAtsQryRecAuthInfo tmpRetAts = new RetAtsQryRecAuthInfo(p_req.reqHeader);
        try {
            tr_code = "FHTS01";
            String transCode = "200101";
            String contractNo = getBankConfig().getMapValueByKey("cagrNo" + transCode, p_req.ownAct);//有问题

            XmlTextWriter xmlWriter = new XmlTextWriter();// 发银行报文的XML对象
            // 写入通用的头部节点
            writeCommonHeader(xmlWriter);
            xmlWriter.writeStartElement("body");
            XElement dataXElemet = new XElement("data", "");
            dataXElemet.addChild(new XElement("transCode", transCode));//交易码
            dataXElemet.addChild(new XElement("sndOrgNo", bankFront.org));//收费机构代码
            dataXElemet.addChild(new XElement("sndBranchNo", ""));//机构分支代码
            dataXElemet.addChild(new XElement("contractno", contractNo));//合同号
            dataXElemet.addChild(new XElement("custno", getValueAsString("custno")));//用户编号
            dataXElemet.addChild(new XElement("cusNme", getValueAsString("cusNme")));//用户名称
            dataXElemet.addChild(new XElement("busKnd", ""));//业务种类
            dataXElemet.addChild(new XElement("bankno", ""));//付款行行号
            dataXElemet.addChild(new XElement("acctno", p_req.oppAct));//付款人账号
            dataXElemet.addChild(new XElement("acctname", p_req.oppName));//付款人名称
            xmlWriter.writeXElement(dataXElemet);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            tmpRetAts.ownAct = p_req.ownAct;
            XmlTextReader tmpBkReader;
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String ans_code = tmpBkReader.getFirstText("/ap/head/ans_code");
                    String responseCode = tmpBkReader.getFirstText("/ap/body/responseCode");
                    if ("0".equals(ans_code)) {
                        if ("000000".equals(responseCode)) {
                            tmpRetAts.respCode = "0";
                            RetAtsQryRecAuthInfoDetail detail = new RetAtsQryRecAuthInfoDetail();
                            detail.oppAct = tmpBkReader.getFirstText("/ap/body/acctno");
                            detail.oppActName = tmpBkReader.getFirstText("/ap/body/acctname");
                            detail.authDateFrom = tmpBkReader.getFirstText("/ap/body/signDate"); //格式YYYYMMDD
                            detail.queryTag = "0".equals(tmpBkReader.getFirstText("/ap/body/status")) ? "1" : "0"; //协议状态 0-无效,1-人行或者本地已签订,2-已激活
                            detail.respReserve1 = "";
                            detail.respReserve2 = "";
                            detail.respReserve3 = "";
                            tmpRetAts.writeRetDetail(detail);
                        } else {
                            tmpRetAts.respCode = "-1";
                        }
                        tmpRetAts.respInfo = tmpBkReader.getFirstText("/ap/body/responseMessage");

                    } else {
                        tmpRetAts.respCode = "-1";
                        tmpRetAts.respInfo = tmpBkReader.getFirstText("/ap/head/ans_info");
                    }
                } else {
                    tmpRetAts.respCode = "-1";
                    tmpRetAts.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetAts.respCode = "-1";
                tmpRetAts.respInfo = tmpStrRet[1];
            }

        } catch (Exception ex) {
            tmpRetAts.respCode = "-1";
            tmpRetAts.respInfo = ex.getMessage();
            ex.printStackTrace();
        }
        tmpRetAts.writeAfterDetail();
        return tmpRetAts;
    }
}
